import React from 'react'
import {textAlignAdapter} from '../utils'
import {ITableColumnConfig} from "@/pages/SelfQuery/type";

interface IBodyCellProps {
  config: ITableColumnConfig
}

function BodyCell(props: IBodyCellProps) {
  const {config, ...rest} = props
  const cellCssStyle = getBodyCellStyle(config)
  return (
    <td style={cellCssStyle} {...rest} />
  )
}

export default BodyCell

function getBodyCellStyle(columnConfig: ITableColumnConfig) {
  const basicStyle = getBasicStyledCell(columnConfig)
  const cellStyle = {...basicStyle}
  return cellStyle
}

function getBasicStyledCell(columnConfig: ITableColumnConfig) {
  if(!columnConfig){
    return {}
  }
  const { fontFamily, fontWeight, fontColor, fontStyle, justifyContent} = columnConfig.style
  const cssStyle: React.CSSProperties = {
    fontFamily,
    fontWeight: fontWeight as React.CSSProperties['fontWeight'],
    color: fontColor,
    fontStyle,
    textAlign: textAlignAdapter(justifyContent)
  }
  return cssStyle
}
